'+++  2893-82  +++
'GCV_FRONT = 2
'GCV_LEFT = 4
'GCV_RIGHT = 5
'GCV_EXTENDED = 7
'GCV_SIMPLIFIED = 8
'GCV_STANDARD = 9
'SIDE = GCV_FRONT

'DETAIL_LEVEL = GCV_SIMPLIFIED'GCV_EXTENDED

hatchAngle  = 45                  
'hatchStep= 2                   

drawFace1 =1

'PAR_din=20
'PAR_d=47
'PAR_b=14
'PAR1_dain= (25+26) * 0.5
'PAR1_da=  42
'PAR1_dw= 7.94
'PAR1_r = 1.5
 
'PAR2_r1 =  0.5
'PAR2_t1 =  2.45
'PAR2_c1 =  1.3
'PAR2_D1 =  44.6

Dim math,iDA,iPoint
Const POINT_ARR = 2  
Const ko_MathPointParam = 14

''PAR_AXIS = 1
''PAR_Simpl_AXIS = 1  

'++++
SUB LINE (x1,y1,x2,y2,t) Doc.ksLineSEG x1,y1,x2,y2,t END SUB
SUB Circle (x1,y1,r,t) Doc.ksCircle x1,y1,r,t END SUB
'++++
SUB DrawBall (xtr, ytr, rads, del)
  Line  xtr-rads-del,ytr,xtr+rads+del,ytr,3
  Line  xtr,ytr+rads+del,xtr,ytr-rads-del,3
 Circle xtr,ytr,rads,1
end sub
'++++

'++++
SUB Script_OnLoad ()

Set math = Kompas.GetMathematic2D
Set iDA = Kompas.GetDynamicArray(POINT_ARR)
Set iPoint = Kompas.GetParamStruct(ko_MathPointParam)



   ys=(  PAR1_dain+ PAR1_Da)*0.25
   xs= PAR_B*0.5                 
   rn= PAR_D*0.5
   rv= PAR_din*0.5
   rv2= PAR1_dain*0.5
   rn2= PAR1_Da*0.5
   rsh =  PAR1_Dw*0.5

  IF  rv2 < (ys-0.8*rsh)  THEN
    rv2 = ys-0.8*rsh 
END IF
  
IF  rn2 > (ys+0.8*rsh) THEN
    rn2 = ys+0.8*rsh
END If

  doc.ksColouring &HFE000000
    Contur rv, rn,  PAR1_r,   PAR_B, 1,  PAR2_r1,  PAR2_t1,  PAR2_c1,  PAR2_D1
    Contur rv, rn,  PAR1_r,   PAR_B, -1,  PAR2_r1,  PAR2_t1,  PAR2_c1,  PAR2_D1
 doc.ksEndObj

SELECT CASE DETAIL_LEVEL
      Case GCV_EXTENDED:

        DrawOutsideRing  rn, rn2,  PAR_B,  PAR1_r, xs, ys, rsh, 1,  PAR2_r1,  PAR2_t1,  PAR2_c1,PAR2_D1
        DrawBall xs, ys, rsh,  2
        DrawInsideRing   rv, rv2,  PAR_B,  PAR1_r, xs, ys, rsh, 1 

        IF PAR_AXIS <> 1 THEN
          line  0, rn- PAR2_r1, 0, rv+ PAR1_r, 1 
          line   PAR_B, rn- PAR1_r,  PAR_B, rv+ PAR1_r, 1 
        END IF

        DrawOutsideRing  rn, rn2,  PAR_B,  PAR1_r, xs, ys, rsh, -1,  PAR2_r1,  PAR2_t1,PAR2_c1,PAR2_D1 
        DrawBall xs, -ys,  PAR1_Dw*0.5,  2
        DrawInsideRing   rv, rv2,  PAR_B,  PAR1_r, xs, ys, rsh, -1 
        IF  PAR_AXIS <> 1 THEN
          line  0, -(rn- PAR2_r1), 0, -(rv+ PAR1_r), 1 
          line  PAR_B, -(rn- PAR1_r), PAR_B, -(rv+ PAR1_r), 1 
        END IF 

       
      case  GCV_STANDARD:

        IF PAR_AXIS = 1 THEN
          DrawOutsideRing rn, rn2,  PAR_B,  PAR1_r, xs,ys,rsh,1,PAR2_r1,PAR2_t1,PAR2_c1,PAR2_D1
          DrawBall xs, ys,  PAR1_Dw*0.5, 2
          DrawInsideRing rv, rv2,  PAR_B,  PAR1_r, xs, ys, rsh, 1 
          IF PAR_AXIS <> 1 THEN
            line  0, rn- PAR2_r1, 0, rv+ PAR1_r, 1 
            line  PAR_B, rn- PAR1_r, PAR_B, rv+ PAR1_r, 1 
          END IF

          DrawSimple rv, rn,  PAR1_r,  PAR_B, -1,  PAR2_r1,  PAR2_t1,  PAR2_c1,  PAR2_D1
        
        ELSE 
          DrawSimple rv, rn,  PAR1_r,  PAR_B, 1,  PAR2_r1,  PAR2_t1,  PAR2_c1,  PAR2_D1
          DrawOutsideRing  rn, rn2, PAR_B,  PAR1_r, xs, ys, rsh, -1,  PAR2_r1,  PAR2_t1,  PAR2_c1,PAR2_D1
          DrawBall  xs, -ys,  PAR1_Dw*0.5,  2
          DrawInsideRing   rv, rv2,  PAR_B,  PAR1_r, xs, ys, rsh, -1 
        IF PAR_AXIS <> 1 THEN
            line  0, -(rn- PAR2_r1), 0, -(rv+ PAR1_r), 1 
            line  PAR_B, -(rn- PAR1_r),  PAR_B, -(rv+ PAR1_r), 1 
        END IF  
        END IF

      CASE GCV_SIMPLIFIED:

        DrawSimple rv, rn,  PAR1_r,   PAR_B, 1,  PAR2_r1,  PAR2_t1,  PAR2_c1,  PAR2_D1
        DrawSimple rv, rn,  PAR1_r,   PAR_B, -1,  PAR2_r1,  PAR2_t1,  PAR2_c1,  PAR2_D1
        
    END SELECT

 iDA.ksDeleteArray

END SUB  
'++++++++++
SUB DrawOutsideRing ( rn,   rn2,  b,  r,  xs,ys,rads,  ky,  r1,  t1,  c1,  d1) 

 y3=(rn-r)*ky
 y2=(rn-r1)*ky
DIM  xp(2), yp(2)

iDA.ksClearArray
 math.ksIntersectLinsCir 0,rn2*ky,b,rn2*ky, xs,ys*ky,rads,iDA
 I = iDA.ksGetArrayCount
  
  doc.ksArcByPoint r1,y2,r1,0,y2,r1,rn*ky,-ky,1
  line r1,rn*ky,t1,rn*ky,1
  line t1, rn*ky, t1, d1*0.5*ky, 1
  line t1, d1*0.5*ky,t1+c1,d1*0.5*ky, 1
  line t1+c1,d1*0.5*ky, t1+c1, rn*ky, 1
  line t1+c1, rn*ky, b-r,rn*ky, 1
   doc.ksArcByPoint b-r,y3,r,b-r,rn*ky,b,y3,-ky,1
  
IF   i <>0 THEN
iDA.ksGetArrayItem 0, iPoint
    xp(0) = iPoint.x
    IF  i = 1  THEN
      Xp(1) = xp(0)
    ELSE 
     iDA.ksGetArrayItem 1, iPoint
      xp(1) = iPoint.x
      IF  xp(1)< xp(0)  THEN
         x = xp(0)
        xp(0) = xp(1)
        xp(1) = x
      END IF 
    END IF

   Line b,rn2*ky,xp(1),rn2*ky,1
   Line xp(0),rn2*ky,0,rn2*ky,1

  
  ELSE
    Line b,rn2*ky, 0,rn2*ky,1 
END IF

                   

Doc.kshatch 0, hatchAngle, hatchStep , 0, 0, 0   
    Line 0,rn2*ky,0,y2,1
    doc.ksArcByPoint r1,y2,r1,0,y2,r1,rn*ky,-ky,1
    line r1,rn*ky,t1,rn*ky,1
    line t1, rn*ky, t1, d1*0.5*ky, 1
    line t1, d1*0.5*ky,t1+c1,d1*0.5*ky, 1
    line t1+c1,d1*0.5*ky, t1+c1, rn*ky, 1
    line t1+c1, rn*ky, b-r,rn*ky, 1
    doc.ksArcByPoint b-r,y3,r,b-r,rn*ky,b,y3,-ky,1
    line b,y3,b,rn2*ky,1

    IF  i <>0 THEN
      Line b,rn2*ky,xp(1),rn2*ky,1
      IF  i>1 THEN
         doc.ksArcByPoint xs,ys*ky,rads,xp(1),rn2*ky,xp(0),rn2*ky,ky,1
      END IF
      Line xp(0),rn2*ky,0,rn2*ky,1
     ELSE
      Line b,rn2*ky, 0,rn2*ky,1 
    END IF
 Doc.ksEndObj

 IF  PAR_AXIS = 1 THEN
   Line b,y3,b,0,1
   Line 0,y2,0,0,1
   IF  ky = 1 THEN
     Line  -2, 0, b+2, 0, 3 
   END IF 
END IF 
END SUB  
'+++++++++++++++++++++=
sub DrawInsideRing ( rv, rv2, b, r, xs,ys, rads, ky ) 
 y2=(rv+r)*ky
   Dim  xp(2) 

  iDA.ksClearArray
  math.ksIntersectLinsCir 0,rv2*ky,b,rv2*ky, xs,ys*ky,rads,iDA
  I = iDA.ksGetArrayCount

  IF  I <>0 THEN  
   iDA.ksGetArrayItem 0, iPoint
   xp(0) = iPoint.x
   
    if i = 1 then
      xp(1) = xp(0)
    else 
      iDA.ksGetArrayItem 1, iPoint
      xp(1) = iPoint.x
      if( xp(1)< xp(0) ) then
         x = xp(0)
        xp(0) = xp(1)
        xp(1) = x
      end if
    end if
    line 0,rv2*ky,xp(0),rv2*ky,1
    line xp(1),rv2*ky,b,rv2*ky,1
  else
    line 0,rv2*ky,b,rv2*ky,1
end if  

  doc.ksArcByPoint b-r,y2,r,b,y2,b-r,rv*ky,-ky,1
  line b-r,rv*ky,r,rv*ky,1
  doc.ksArcByPoint r,y2,r,r,rv*ky,0,y2,-ky,1

 If PAR_AXIS = 1 THEN
    line r,rv*ky,r,0,1
   line b-r,rv*ky,b-r,0,1
 End if

  Doc.kshatch  0, hatchAngle-90, hatchStep, 0, 0, 0
    line b,rv2*ky,b,y2,1
    doc.ksArcByPoint b-r,y2,r,b,y2,b-r,rv*ky,-ky,1
    line b-r,rv*ky,r,rv*ky,1
    doc.ksArcByPoint r,y2,r,r,rv*ky,0,y2,-ky,1
    line 0,y2,0,rv2*ky,1

  IF  i <>0  THEN
     line 0,rv2*ky,xp(0),rv2*ky,1
      IF  i > 1 THEN
      doc.ksArcByPoint xs,ys*ky,rads,xp(0),rv2*ky,xp(1),rv2*ky,ky,1
      end if
      line xp(1),rv2*ky,b,rv2*ky,1

    else
      line 0,rv2*ky,b,rv2*ky,1
   end if


    Doc.ksEndObj

 end sub 

'++++++++
 SUB DrawSimple( rv, rn, r,b, ky,  r1,  t1,  c1,  d1)

 x1=r
 x2=r1
 x3=b-r
 x4=b-r

 y1=(rv+r)*ky
 y2=(rn-r1)*ky
 y3=(rn-r)*ky
 y4=(rv+r)*ky

  line 0,y1,0,y2,1
   doc.ksArcByPoint x2,y2,r1,0,y2,x2,rn*ky,-ky,1


  line x2,rn*ky,t1,rn*ky,1
  line t1, rn*ky, t1, d1*0.5*ky, 1
  line t1, d1*0.5*ky,t1+c1,d1*0.5*ky, 1
  line t1+c1,d1*0.5*ky, t1+c1, rn*ky, 1
  line t1+c1, rn*ky, x3,rn*ky, 1

   doc.ksArcByPoint x3,y3,r,x3,rn*ky,b,y3,-ky,1
  line b,y3,b,y4,1 
   doc.ksArcByPoint x4,y4,r,b,y4,x4,rv*ky,-ky,1
  line x4,rv*ky,x1,rv*ky,1
   doc.ksArcByPoint x1,y1,r,x1,rv*ky,0,y1,-ky,1  
   
If PAR_Simpl_AXIS = 1 Then    
  line x1,y1,x3,y3,2
  line x1,y3,x4,y4,2 
 Else  
  ''NEW 
   Line b/3,(rn+rv)*0.5*ky,2*b/3,(rn+rv)*0.5*ky,2
   Line b*0.5,((rn+rv)*0.5-b/6)*ky,b*0.5,((rn+rv)*0.5+b/6)*ky,2
   ''
End If   
 
  If PAR_AXIS = 1 Then 
    line b,0,b,y4,1
    line x1,0,x1,rv*ky,1
    line x4,0,x4,rv*ky,1

    line 0,y1,0,0,1
     IF  ky = 1  THEN
      Line  -2, 0, b+2, 0, 3
     END IF
 End IF
END SUB
'++++++++++++
'++++++++++++++
SUB Contur ( rv, rn, r,b, ky,  r1,  t1,  c1,  d1) 

 x1=r
 x2=r1
 x3=b-r
 x4=b-r

 y1=(rv+r)*ky
 y2=(rn-r1)*ky
 y3=(rn-r)*ky
 y4=(rv+r)*ky

  line 0,y1,0,y2,1
  doc.ksArcByPoint x2,y2,r1,0,y2,x2,rn*ky,-ky,1
  Line x2,rn*ky,t1,rn*ky,1
  Line t1, rn*ky, t1, d1*0.5*ky, 1
  Line t1, d1*0.5*ky,t1+c1,d1*0.5*ky, 1
  Line t1+c1,d1*0.5*ky, t1+c1, rn*ky, 1
  Line t1+c1, rn*ky, x3,rn*ky, 1
   doc.ksArcByPoint x3,y3,r,x3,rn*ky,b,y3,-ky,1
    Line b,y3,b,y4,1 
    Line b,0,b,y4,1
    Line 0,y1,0,0,1

END SUB
'++++
